<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>axios基本使用</title>
		<script src="https://unpkg.com/axios/dist/axios.min.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		网易云接口：https://autumnfish.cn/
		

		<input type="button" value="get请求" class="get" />
		<input type="button" value="post请求" class="post" />

		<script type="text/javascript">
			// 随机获取笑话条数
			document.querySelector(".get").onclick = function() {
				axios.get("https://autumnfish.cn/api/joke/list?num=6")
				// axios.get("https://autumnfish.cn/api/joke/list12312?num=6")
				.then(function(response) {
					console.log(response)
				},function(err){
					console.log("错误："+err)
				})
			}
			
			//用户注册
			document.querySelector(".post").onclick = function(){
				axios.post("https://autumnfish.cn/api/user/reg",{username:"jack"})
				// axios.post("https://autumnfish.cn/api/user/reg111",{username:"jack"})	//示范错误
				.then(function(response){
					console.log(response);
				},function(err){
					console.log(err)
				})
			}
			
		</script>
	</body>
</html>
